﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AzureGames.Data;
using AzureGames.Domain.Models;
using AzureGames.Domain.Contracts;

namespace AzureGames.Domain.Handlers
{
    /// <summary>
    /// used to return a model containing the options for extending a game of a specified game definition in relation to the current player
    /// </summary>
    public class GetGameExtend
    {
        private readonly IGameDefinitionRepository _gameDefinitionRepository;

        public GetGameExtend(IGameDefinitionRepository gameDefinitionRepository)
        {
            _gameDefinitionRepository = gameDefinitionRepository;
        }

        public virtual GameDefinition Execute(int gameDefinitionID, string playerID)
        {
            try
            {
                // if the player is unauthenticated
                //    message is returned to explain the basic process of extending a game and that this is
                //    only available to authenticated users
                // if the player is authenticated
                //    returns a collection of currently active AI scripts
                //    returns a collection of currently deployed AI scripts that belong to the user
                // remark: the concept is the player can then pick a particular one then be 
                //         transfered to a new framed page allowing the change to be applied.

                return new GameDefinition(_gameDefinitionRepository.GetGameDefinition(gameDefinitionID));
            }
            catch (InvalidOperationException e)
            {
                throw new BusinessServicesException("Unable to retrieve game definition from database.", e);
            }
        }
    }
}
